{extend name="public/base"/}
{block name="style"}
<link href="__PUBLIC__/ieasy/css/recently.css?v=2.1.49" rel="stylesheet" type="text/css">
<link href="__PUBLIC__/ieasy/css/classify.css?v=2.1.49" rel="stylesheet" type="text/css">
{/block}
{block name="body"}
<div id="console_main"></div>
<div class="head_tit_box">
	<a href="javascript:;" class="head_return_page_but"></a>
		<div class="head_menu_but_box">
		<a href="javascript:;" class="head_menu_but"></a>
	</div>
		<h1>{empty name="catename"}
				{switch name="top" }
					{case value="9"}本周强推{/case}
					{case value="8"}主编力荐{/case}
					{case value="5"}读者推荐{/case}
					{case value="3"}小说精选{/case}
					{case value="2"}新书推荐{/case}
				{/switch}
			{else /}
				{$catename}
			{/empty}</h1>
</div>
<!--导航-->
{block name="include"}{include file="public:dropnav" /}{/block}
<!-- 这是正文 -->

<div class="body_sytle">
	
	<div class="c_list_box">
		
		<div class="c_list_tab_box_2">
			<a href="javascript:;" class="hover" type="">全部</a>
			<a href="javascript:;" type="0">连载</a>
			<a href="javascript:;" type="1">完本</a>
			<a href="javascript:;" type="free">免费</a>
		</div>
		
		<ul class="r_img_ul"></ul>
	</div>
	<div class="loading_box"><span>正在加载中，请稍后......</span></div> 
	
	<div class="content_null_box" style="display: none;">
		<img src="__PUBLIC__/ieasy/img/icon_16.png" style="width: 1.28rem;" />
		<span>暂无该类别图书，换个条件试试看吧！</span>
		<div class="content_null_but_box">
			<a href="/">去首页看看</a>
		</div>
	</div>
	
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.min.js?v=2.1.49"></script>
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.cookie.min.js?v=2.1.49"></script>

<!-- 这是zepto插件 -->
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.picLazyLoad.min.js?v=2.1.49"></script>

<script type="text/javascript" src="__PUBLIC__/ieasy/js/common.js?v=2.1.49"></script>
<script type="text/javascript" src="__PUBLIC__/ieasy/js/cps_log.js?v=2.1.49"></script>
<script type="text/javascript">
	var start=0, 
		limit=10,
		cate = {$cate|default=0},
		is_top = {$top|default=0},
		channel = {$channel},
		fullflag = '{$fullflag}',
		sBookstop=true, 
		sBookstopTime=null, 
		pagesize=10;
		//type = $(".c_list_tab_box_2 a").eq(0).attr('type');

	$(function(){
		loadingList();
		$(".c_list_tab_box_2 > a").click(function(){
			$(this).addClass("hover");
			$(this).siblings().removeClass("hover");
			$('.r_img_ul').html('').show();
			$('.content_null_box').hide();
			$('.loading_box').html('<span>正在加載中，请稍候......</span>').show();
			fullflag = $(this).attr("type");
			sBookstop = true;
			pagenum = 1;
			start=0;
			limit=10;
			loadingList();
		});
		
		$(window).scroll(function(){
			var nWinH =  document.documentElement.clientHeight;
			var nScrollTop = (document.body.scrollTop || document.documentElement.scrollTop) + nWinH;
			var nBodyScrollH = document.body.scrollHeight;
			if(sBookstop && nBodyScrollH - nScrollTop < 240){
				bookstoptime();
				$('.loading_box').html('<span>正在加載中，请稍候......</span>').show();
				loadingList();
			}
		});
	});

	function loadingList(){
		$.ajax({
			type: 'get',
			url: '/api/index/allbooks/',
			timeout: 500,
			cache: false,
			dataType: 'json',
			data: {
				'top':is_top,
				'channel':channel,
				'cate':cate,
				'fullflag':fullflag,
				'start': start,
        		'limit': limit
			},
			success: function (json) {
                var total=json.data.total;
				data=json.data.data;
				clearTimeout(sBookstopTime);
				if (typeof data == 'string') {
					data = JSON.parse(data);
				}
				if(data<=0 && pagenum == 1){
					$('.r_img_ul,.loading_box').hide();
					$('.content_null_box').show();
					sBookstop = false;
					return false;
				}
				var sLi = '';
				for(var i=0; i<data.length; i++){
					sLi += '<li>\
						<a href="'+ data[i]['link'] +'">\
							<div class="r_img">\
								<img src="" data-original="'+ data[i]['cover'] +'" />\
							</div>\
							<div class="r_img_text">\
								<h3>'+ data[i]['title'] +'</h3>\
								<p>'+ data[i]['desc'] +'</p>\
								<div class="r_img_other">\
									<i>'+ data[i]['author'] +'</i>\
									<strong>'+ data[i]['allvisit'] +'人在追</strong>\
								</div>\
							</div>\
						</a>\
					</li>';
				}
				$('.r_img_ul').append(sLi); 
               // alert(start+'---'+total);
				start =start+10; 
				if(start>=total){
					$('.loading_box').html('<span>已显示全部</span>').show();
					sBookstop = false;
				}else{
					$('.loading_box').html('<span>下拉加载更多</span>').show();
					sBookstop = true;
				}	
				$('img').picLazyLoad({
					effect : "fadeIn"
				});

			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				$('.loading_box').html('<span>已显示全部</span>').show();
				sBookstop = false;
			}
		});
	}

	//防止重复请求数据
	function bookstoptime() {
		clearTimeout(sBookstopTime);
		sBookstop = false;
		sBookstopTime = setTimeout(function () {
			sBookstop = true;
		}, 3000);
	}
</script>
{/block}